#include "workdialog.h"
#include "ui_workdialog.h"
#include<QString>
#include<QDebug>
#include<QMessageBox>
#include<QSqlDatabase>
#include"qualifydocu.h"
#include"sqlconnect.h"
workDialog::workDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::workDialog)
{
    ui->setupUi(this);
    connect(ui->cancel,SIGNAL(clicked(bool)),this,SLOT(close()));
    connect(ui->confirm,SIGNAL(clicked(bool)),this,SLOT(react()));
    connect(ui->confirm,SIGNAL(clicked(bool)),parent,SLOT(showWorkInfo()));
}

workDialog::~workDialog()
{
    delete ui;
}
void workDialog::react(){
    QString start=ui->startDate->date().toString(Qt::ISODate);
    QString end=ui->endDate->date().toString(Qt::ISODate);
    QString unit=ui->unitEdit->text();
    QString work=ui->workEdit->text();
    if(unit.count()==0||work.count()==0){
        QMessageBox::information(this,"提示信息","输入有空项！");
        return;
        }
    //qDebug()<<start<<" "<<end;
    //sqlconnect(db);
    QSqlQuery qu("select * FROM `Experience` WHERE StartTime='"+start+"' and IDNum= '"+ID+"'");
    if(qu.next())
    {
        QMessageBox::information(this,"提示信息","该条工作经历已存在，不可重复添加！");
        return;
    }

    QSqlQuery query;
    QString sql="INSERT INTO `Experience`(StartTime,EndTime,UnitName,PostName,IDNum)VALUES('"+start+"','"+end+"','"+unit+"','"+work+"','"+ID+"')";
    bool ok=query.exec(sql);
    //qDebug()<<ok;
    if(ok){
        QMessageBox::information(this,"提示信息","成功插入!");
    }

    //db.close();
    this->close();
}

void workDialog::reciveID(QString s){
    ID=s;
}
